<template>
    <div>
<table>
    <tbody>
        <tr>
            <td>姓名</td>
            <td>
                <input type="text" name="" v-model="date.name" id="">
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" name="" v-model="date.pwd" id="">
            </td>
        </tr>
        <tr>
            <td colspan="2">
<input type="button" value="登录" @click="add">
            </td>
            
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import {useCounterStore} from '@/stores/counter'
import {  useRouter } from 'vue-router';

const emps=useCounterStore();
const router=useRouter()

const add=()=>{
    axios.get('https://localhost:7259/api/Emp',{params:date.value}).then(res=>{
        if(res.data.id==-1){
            alert('用户不存在')
            return;
        }else if(res.data.id==-2){
            alert('密码错误')
            return;
        }else if(res.data.id>0){
            alert('登录成功')
emps.emp.name=date.value.name
emps.emp.state=true;
router.push({path:"/show"})
          
        }else{
            alert('登录失败')
            return;
        }
    })
}
const date=ref({
   
  name:"",
  pwd:""
})



</script>

<style scoped>

</style>